import 'package:acgn_pioneer/plugin/dialog/src/constants.dart';
import 'package:acgn_pioneer/plugin/dialog/src/dialog.dart';
import 'package:acgn_pioneer/providers/pop_slide_provider.dart';

import '../public.dart';

/// 弹窗
class PopUtil {
  static void show(BuildContext context, Widget widget,
      {EdgeInsets padding,
      Alignment alignment = Alignment.topCenter,
      DialogTransition transition}) {
    ACGNDialog(context,
            alignment: alignment,
            clipBehavior: Clip.antiAlias,
            backgroundColor: Color(0xff1B1B26),
            transition: transition,
            shape: RoundedRectangleBorder(
              side: BorderSide.none,
            ),
            barrier: DialogBarrier(
                barrierDismissible: true,
                barrierColor: ColorUtil.rgba(0, 0, 0, 0.25)),
            body:
                DialogBody(isScorll: false, content: widget, padding: padding))
        .show();
  }

  // 底部滑动弹窗
  static Future<T> showSlidePop<T>(
      {@required BuildContext context,
      @required Widget child,
      Color barrierColor,
      bool barrierDismissible = true,
      Duration transitionDuration = const Duration(milliseconds: 300),
      Color backgroundColor}) {
    assert(context != null);
    assert(child != null);

    return showGeneralDialog(
      context: context,
      pageBuilder: (context, animation1, animation2) {},
      barrierColor: barrierColor ?? Colors.black.withOpacity(0.7),
      barrierDismissible: barrierDismissible,
      barrierLabel: "Dismiss",
      transitionDuration: transitionDuration,
      transitionBuilder: (context, animation1, animation2, widget) {
        final curvedValue = Curves.easeInOut.transform(animation1.value) - 1.0;
        return Transform(
            transform: Matrix4.translationValues(0.0, curvedValue * -300, 0.0),
            child: Opacity(
              opacity: animation1.value,
              child: ChangeNotifierProvider<PopSlideProvider>(
                create: (context) => PopSlideProvider(),
                child: SlideDialogComponent(child: child),
              ),
            ));
      },
    );
  }
}
